/*     */ package com.chinapay.secss.util;
/*     */ 
/*     */ import java.security.Key;
/*     */ import javax.crypto.Cipher;
/*     */ import javax.crypto.spec.SecretKeySpec;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class JiaMiUtil
/*     */ {
/*     */   public JiaMiUtil() throws Exception {
/*  20 */     this(strDefaultKey);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public JiaMiUtil(String strKey) throws Exception {
/*  31 */     SecretKeySpec key = new SecretKeySpec(getKey(strKey), "DES");
/*  32 */     this.encryptCipher = Cipher.getInstance("DES/ECB/NoPadding");
/*  33 */     this.encryptCipher.init(1, key);
/*  34 */     this.decryptCipher = Cipher.getInstance("DES/ECB/NoPadding");
/*  35 */     this.decryptCipher.init(2, key);
/*     */   }
/*     */   
/*  38 */   private static String strDefaultKey = "javashop8864";
/*     */   
/*  40 */   private Cipher encryptCipher = null;
/*     */   
/*  42 */   private Cipher decryptCipher = null;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String byteArr2HexStr(byte[] arrB) throws Exception {
/*  51 */     int iLen = arrB.length;
/*     */     
/*  53 */     StringBuffer sb = new StringBuffer(iLen * 2);
/*  54 */     for (int i = 0; i < iLen; i++) {
/*  55 */       int intTmp = arrB[i];
/*     */       
/*  57 */       while (intTmp < 0) {
/*  58 */         intTmp += 256;
/*     */       }
/*     */       
/*  61 */       if (intTmp < 16) {
/*  62 */         sb.append("0");
/*     */       }
/*  64 */       sb.append(Integer.toString(intTmp, 16));
/*     */     } 
/*  66 */     return sb.toString();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static byte[] hexStr2ByteArr(String strIn) throws Exception {
/*  75 */     byte[] arrB = strIn.getBytes();
/*  76 */     int iLen = arrB.length;
/*     */     
/*  78 */     byte[] arrOut = new byte[iLen / 2]; int i;
/*  79 */     for (i = 0; i < iLen; i += 2) {
/*  80 */       String strTmp = new String(arrB, i, 2);
/*  81 */       arrOut[i / 2] = (byte)Integer.parseInt(strTmp, 16);
/*     */     } 
/*  83 */     return arrOut;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public byte[] encrypt(byte[] arrB) throws Exception {
/*  91 */     int count = arrB.length % 8;
/*  92 */     if (count > 0) {
/*  93 */       StringBuffer str = new StringBuffer(new String(arrB));
/*  94 */       for (int i = 0; i < 8 - count; i++) {
/*  95 */         str.append(" ");
/*     */       }
/*  97 */       return this.encryptCipher.doFinal(str.toString().getBytes());
/*     */     } 
/*  99 */     return this.encryptCipher.doFinal(arrB);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String encrypt(String strIn) throws Exception {
/* 107 */     return byteArr2HexStr(encrypt(strIn.getBytes()));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public byte[] decrypt(byte[] arrB) throws Exception {
/* 115 */     return this.decryptCipher.doFinal(arrB);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public String decrypt(String strIn) throws Exception {
/* 123 */     return new String(decrypt(hexStr2ByteArr(strIn)));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private byte[] getKey(String keyRule) throws Exception {
/* 131 */     Key key = null;
/* 132 */     byte[] keyByte = keyRule.getBytes();
/*     */     
/* 134 */     byte[] byteTemp = new byte[8];
/*     */     
/* 136 */     for (int i = 0; i < byteTemp.length && i < keyByte.length; i++) {
/* 137 */       byteTemp[i] = keyByte[i];
/*     */     }
/* 139 */     key = new SecretKeySpec(byteTemp, "DES");
/* 140 */     return key.getEncoded();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String encryptCode(String string) {
/*     */     try {
/* 149 */       JiaMiUtil des1 = new JiaMiUtil();
/* 150 */       return des1.encrypt(string);
/* 151 */     } catch (Exception e) {
/*     */       
/* 153 */       return "";
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static String decryptCode(String string) {
/*     */     try {
/* 163 */       JiaMiUtil des1 = new JiaMiUtil();
/* 164 */       return des1.decrypt(string).trim();
/* 165 */     } catch (Exception e) {
/* 166 */       return "";
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   public static void main(String[] args) {
/* 172 */     /*String str = "http://record.javamall.com.cn/data/installer";
*//* 173 *//*     str = encryptCode(str);
*//* 174 *//*     System.out.println(str)*/;
/*     */   }
/*     */ }


/* Location:              C:\Users\Administrator\Downloads\jd-gui-windows-1.6.6\jd-gui-windows-1.6.6\chinapay-secure-1.5.1.jar!\com\chinapay\secs\\util\JiaMiUtil.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       1.1.3
 */